//
//  EightViewController.m
//  项目二
//
//  Created by rimi on 16/5/13.
//  Copyright © 2016年 objective. All rights reserved.
//

#import "EightViewController.h"
#import "Datai1ViewController.h"
#define contentString @"23243543dfasdsasadcxvfh"
static NSString *const conton = @"dsadsafasdasdasfgaavdpfjghdnsohdoasnd";
//2.引入协议名
@interface EightViewController ()<UITextFieldDelegate>

@end

@implementation EightViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"回顾协议";
    self.view.backgroundColor = [UIColor whiteColor];
    [self initButtonInterface];
    [self initlightButtonInterface];
    [self initUITextFieldInterface];
    [self initUILabelInterface];
    
}
-(void)initUILabelInterface{
    
    //不做文本自适应的标签
    UILabel *leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 350, 170, 20)];
    leftLabel.backgroundColor = [UIColor orangeColor];
    leftLabel.font = [UIFont systemFontOfSize:17];
    leftLabel.text = conton;
    leftLabel.numberOfLines = 0;
    leftLabel.tag = 300;
    [self.view addSubview:leftLabel];
    
    //做文本自适应的标签
    UILabel *rightLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 500, CGRectGetWidth(self.view.bounds)-10, 40)];
    rightLabel.backgroundColor = [UIColor whiteColor];
    rightLabel.font = [UIFont systemFontOfSize:17];
    rightLabel.text = conton;
    rightLabel.numberOfLines = 0;
    rightLabel.tag = 301;
    [self.view addSubview:rightLabel];
    //文本自适应
    [rightLabel sizeToFit];

}
- (void)initUITextFieldInterface{
    //文本框
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(30, 200, 200, 40)];
    //1.设置代理，让谁实现协议方法，就把谁设置为代理对象
    textField.delegate = self;
    textField.borderStyle = UITextBorderStyleLine;
    textField.placeholder = @"请输入文本";
    //键盘类型
    textField.keyboardType = UIKeyboardTypeASCIICapable;
    //设置清除按钮模式
    textField.clearButtonMode = UITextFieldViewModeAlways;
    //设置安全输入模式
    textField.secureTextEntry = NO;
    [self.view addSubview:textField];

}
- (void)initlightButtonInterface{
    //开关灯按钮
    UIButton *lightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    lightButton.frame = CGRectMake(100, 150, 40, 40);
    //设置按钮图片
    //正常状态下
    [lightButton setImage:[UIImage imageNamed:@"关灯副本.png"] forState:UIControlStateNormal];
    //选中状态下
    [lightButton setImage:[UIImage imageNamed:@"开灯副本.png"] forState:UIControlStateSelected];
    //设置背景图片和设置图片有啥区别？
    //    lightButton setBackgroundImage:<#(nullable UIImage *)#> forState:<#(UIControlState)#>
    [lightButton addTarget:self action:@selector(lightButtonTaped:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:lightButton];
}

- (void)initButtonInterface{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CRM(100, 100, 100, 50);
    button.backgroundColor = [UIColor orangeColor];
    [button setTitle:@"去" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonT:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

#pragma mark - UIButton
-(void)buttonT:(UIButton *)sender{
    Datai1ViewController *datai1 = [[Datai1ViewController alloc]init];
    [self.navigationController pushViewController:datai1 animated:YES];
}
- (void)lightButtonTaped:(UIButton *)sender{
    sender.selected = !sender.selected;
    self.view.backgroundColor = sender.selected ? [UIColor redColor] :[UIColor orangeColor];
}

#pragma mrak - UITextFieldDelegate
//3.实现协议方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    UILabel *currentLeftLabel =  [self.view viewWithTag:300];
    UILabel *currentRightLabel = [self.view viewWithTag:301];
    //赋值
    currentLeftLabel.text = textField.text;
    currentRightLabel.text = textField.text;
    
    [currentRightLabel sizeToFit];
    
    //回收键盘
    [textField resignFirstResponder];
    
    return YES;
}

@end
